	package com.edfu.core.testmgt.persistence.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

@Entity
@Table(name = "question", uniqueConstraints = @UniqueConstraint(columnNames = {"code"}))
public class QuestionEntity implements ITestMgtEntity {
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private long id;
	
	@Column(name = "code", length = 30, nullable = false)
	private String code;
	
	@Column(name = "question", nullable = false)
	private String question;
	
	private String description;
	
	private String solution;
	
	@ManyToMany(mappedBy = "questions")
	private Set<TestEntity> tests = new HashSet<TestEntity>();
	
	@OneToMany(mappedBy = "question", fetch = FetchType.EAGER, cascade = CascadeType.ALL )
	private Set<OptionEntity> options = new HashSet<OptionEntity>();
	
	@OneToMany(mappedBy = "question", fetch = FetchType.EAGER, cascade = CascadeType.ALL )
	private Set<AnswersEntity> answers = new HashSet<AnswersEntity>();
	
	@ManyToOne
	@JoinColumn(name = "question_type_id", nullable = false)
	private QuestionTypeEntity questionType;
	
	@ManyToOne
	@JoinColumn(name = "format_type_id", nullable = false)
	private FormatTypeEntity formatType;
	
	private double positiveMarks;
	
	private double negativeMarks;
	
//	private boolean objective;
	
	private boolean active = true;
	
	private long duration;
	
	private double difficultyLevel;
	private double discriminatoryPower;
	private double guessingFactor;

	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}

	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}

	public String getQuestion() {
		return question;
	}
	public void setQuestion(String question) {
		this.question = question;
	}

	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	
	public String getSolution() {
		return solution;
	}
	public void setSolution(String solution) {
		this.solution = solution;
	}
	
	public Set<TestEntity> getTests() {
		return tests;
	}
	public void setTests(Set<TestEntity> tests) {
		this.tests = tests;
	}
	
	public QuestionTypeEntity getQuestionType() {
		return questionType;
	}
	public void setQuestionType(QuestionTypeEntity questionType) {
		this.questionType = questionType;
	}	

	public FormatTypeEntity getFormatType() {
		return formatType;
	}
	public void setFormatType(FormatTypeEntity formatType) {
		this.formatType = formatType;
	}
	
	public double getPositiveMarks() {
		return positiveMarks;
	}
	public void setPositiveMarks(double positiveMarks) {
		this.positiveMarks = positiveMarks;
	}

	public double getNegativeMarks() {
		return negativeMarks;
	}
	public void setNegativeMarks(double negativeMarks) {
		this.negativeMarks = negativeMarks;
	}

	public Set<OptionEntity> getOptions() {
		return options;
	}
	public void setOptions(Set<OptionEntity> options) {
		this.options = options;
	}
	
	public Set<AnswersEntity> getAnswers() {
		return answers;
	}
	public void setAnswers(Set<AnswersEntity> answers) {
		this.answers = answers;
	}	
	
	public boolean isActive() {
		return active;
	}
	public void setActive(boolean active) {
		this.active = active;
	}
	
	public long getDuration() {
		return duration;
	}
	public void setDuration(long duration) {
		this.duration = duration;
	}
	
	public double getDifficultyLevel() {
		return difficultyLevel;
	}
	public void setDifficultyLevel(double difficultyLevel) {
		this.difficultyLevel = difficultyLevel;
	}
	
	public double getDiscriminatoryPower() {
		return discriminatoryPower;
	}
	public void setDiscriminatoryPower(double discriminatoryPower) {
		this.discriminatoryPower = discriminatoryPower;
	}
	
	public double getGuessingFactor() {
		return guessingFactor;
	}
	public void setGuessingFactor(double guessingFactor) {
		this.guessingFactor = guessingFactor;
	}
	
	@Override
	public String toString() {
		return "QuestionEntity [code=" + code + ", question=" + question + "]";
	}
	
}
